//
//  PayOrderViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/8.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "PayOrderViewController.h"

@interface PayOrderViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;

@end

@implementation PayOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"订单支付";
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark 页面相关
- (void)initPageControl{
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(@0);
    }];
}

#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return section==0?2:3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section==0?10:50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0&&indexPath.row==1) {
        return 40;
    }
    return 60;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==1) {
        
        UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        
        UILabel *label = [[UILabel alloc]init];
        label.font = [UIFont systemFontOfSize:15];
        label.text = @"选择支付方式";
        [headView addSubview:label];
        [label makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            make.centerY.equalTo(headView.centerY);
        }];
        return headView;
    }
    return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *iden = @"iden";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
    }
    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    if (indexPath.section==0&&indexPath.row==1) {
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.textColor = kTitleColor;
        titleLabel.text = @"待付金额:";
        [cell.contentView addSubview:titleLabel];
        [titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.height.equalTo(@30);
            make.width.equalTo(@100);
            make.centerY.equalTo(cell.contentView.centerY);
        }];
        
        UILabel *detailLabel = [[UILabel alloc]init];
        detailLabel.font = [UIFont systemFontOfSize:15];
        detailLabel.textColor = kMainOriginColor;
        detailLabel.text = @"￥500.00";
        [cell.contentView addSubview:detailLabel];
        [detailLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@90);
            make.height.equalTo(@30);
            make.width.equalTo(@200);
            make.centerY.equalTo(cell.contentView.centerY);
        }];
    }
    else{
        
        UIImageView *imgView = [[UIImageView alloc]init];
        imgView.image= [UIImage imageNamed:@"user_setting"];
        [cell.contentView addSubview:imgView];
        [imgView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.centerY.equalTo(cell.contentView.centerY);
            make.width.equalTo(@30);
            make.height.equalTo(@30);
        }];
        
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.textColor = kTitleColor;
        [cell.contentView addSubview:titleLabel];
        [titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imgView.right).offset(10);
            make.height.equalTo(@30);
            make.right.equalTo(@-30);
            make.top.equalTo(@5);
        }];
        
        UILabel *detailLabel = [[UILabel alloc]init];
        detailLabel.font = [UIFont systemFontOfSize:12];
        detailLabel.textColor = kSecTitleColor;
        [cell.contentView addSubview:detailLabel];
        [detailLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel.left);
            make.height.equalTo(@30);
            make.right.equalTo(titleLabel.right);
            make.bottom.equalTo(@-5);
        }];
        if (indexPath.section==0) {
            titleLabel.text = @"提交成功，请尽快完成担保或支付！";
            detailLabel.text = @"房屋未您保留45分钟，请及时付款。";
        }
        else{
            
            UIImageView *imgView = [[UIImageView alloc]init];
            imgView.image= [UIImage imageNamed:@"arrow_detail"];
            [cell.contentView addSubview:imgView];
            [imgView makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(@-10);
                make.centerY.equalTo(cell.contentView.centerY);
                make.width.equalTo(@8);
                make.height.equalTo(@15);
            }];
            
            if (indexPath.row==0) {
                titleLabel.text = @"支付宝支付";
                detailLabel.text = @"发生退款0-5个工作日到账，推荐使用";
            }
            else if (indexPath.row==1) {
                titleLabel.text = @"微信支付";
                detailLabel.text = @"发生退款0-5个工作日到账，推荐使用";
            }
            else if (indexPath.row==2) {
                titleLabel.text = @"银联支付";
                detailLabel.text = @"发生退款2-5个工作日到账";
            }
        }
        
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
   
}

#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorColor = kLineColor;
        _listTableView.backgroundColor = [UIColor clearColor];
        
    }
    
    return _listTableView;
}

@end
